﻿using System;
using System.Configuration;

namespace Hxsoft.AppV1
{
	public partial class ApplicationConfigurationSection
	{
		#region SystemIntegration Property
		public global::Hxsoft.AppV1.SystemIntegrationSection SystemIntegration
		{
			get
			{
				return SystemIntegrationSection.Instance;
			}
		}
		#endregion

		#region Special Property
		public global::Hxsoft.AppV1.SpecialSection Special
		{
			get
			{
				return SpecialSection.Instance;
			}
		}
		#endregion

		#region SystemInit Property
		public global::Hxsoft.AppV1.SystemInitSection SystemInit
		{
			get
			{
				return SystemInitSection.Instance;
			}
		}

		#endregion

		#region ContentUrl Property
		public global::Hxsoft.AppV1.ContentUrlSection ContentUrl
		{
			get
			{
				return ContentUrlSection.Instance;
			}
		}

		#endregion

		#region DictionaryRule Property
		public global::Hxsoft.AppV1.DictionaryRuleSection DictionaryRule
		{
			get
			{
				return DictionaryRuleSection.Instance;
			}
		}

		#endregion

		#region UploadRule Property
		public global::Hxsoft.AppV1.UploadRuleSection UploadRule
		{
			get
			{
				return UploadRuleSection.Instance;
			}
		}

		#endregion

		#region InfoResourceThumbnail Property
		public global::Hxsoft.AppV1.InfoResourceThumbnailSection InfoResourceThumbnail
		{
			get
			{
				return InfoResourceThumbnailSection.Instance;
			}
		}

		#endregion
	}

	public partial class SystemIntegrationSection
	{
		public global::Hxsoft.AppV1.UserIntegrationSection UserIntegration
		{
			get
			{
				return UserIntegrationSection.Instance;
			}
		}
	}





	partial class DictionaryElement
	{
		/// <summary>
		/// 取得字典值的掩码集合。
		/// </summary>
		/// <returns>字典值的掩码集合。</returns>
		/// <remarks>
		/// 如 000000（省市县分别占两位）则返回
		/// long[] = { 10000, 100, 1 }
		/// </remarks>
		public long[] GetMaskCodes()
		{
			long[] codes = new long[Occupys.Count];

			int occupy = 0;
			for (int i = Occupys.Count - 1; i >= 0; i--)
			{
				codes[i] = (long)Math.Pow(10, occupy);
				occupy += Occupys[i].Occupy;
			}

			return codes;
		}

		/// <summary>
		/// 取得指定占位项的掩码值。
		/// </summary>
		/// <param name="name">指定的占位项名称。</param>
		/// <returns>指定占位项的掩码值。</returns>
		/// <remarks>
		/// 如 000000（省市县分别占两位）参数为 name = "省" 则返回 10000。
		/// </remarks>
		public long GetMaskCode(string name)
		{
			int maskOccupy = Occupys.GetMaskOccupy(name);
			return (long)Math.Pow(10, maskOccupy);
		}

		/// <summary>
		/// 取得当前字典值所对应的掩码值。
		/// </summary>
		/// <param name="value">字典值。</param>
		/// <returns>当前字典值所对应的掩码值。</returns>
		/// <remarks>
		/// 如 000000（省市县分别占两位）参数为 value = 450000 则返回 10000。
		/// </remarks>
		public long GetMaskCode(long value)
		{
			const long CustomCode = 1;

			if (value == 0) return CustomCode;

			int occupyNum = 0;
			long code = CustomCode;
			for (int i = Occupys.Count - 1; i >= 0; i--)
			{
				DictionaryOccupyElement occupy = Occupys[i];
				occupyNum += occupy.Occupy;
				code = (long)Math.Pow(10, occupyNum);

				if (value / code * code != value)
				{
					occupyNum -= occupy.Occupy;
					code = (long)Math.Pow(10, occupyNum);
					break;
				}
			}

			return code;
		}
	}

	partial class DictionaryElementCollection
	{
		public DictionaryElement GetItem(string name)
		{
			return (DictionaryElement)BaseGet(name);
		}
	}

	partial class DictionaryOccupyElementCollection
	{
		/// <summary>
		/// 取得指定占位项的掩码占位数。
		/// </summary>
		/// <param name="name">指定的占位项名称。</param>
		/// <returns>指向占位项的掩码占位数。</returns>
		/// <remarks>
		/// 如 000000（省市县分别占两位）则返回4。
		/// </remarks>
		public int GetMaskOccupy(string name)
		{
			int maskOccupy = 0;
			bool isFind = false;
			for (int i = 0; i < this.Count; i++)
			{
				DictionaryOccupyElement item = this[i];
				if (!isFind)
				{
					if (item.Name == name) isFind = true;
				}
				else
				{
					maskOccupy += item.Occupy;
				}
			}

			return maskOccupy;
		}

		/// <summary>
		/// 取得项的索引值。
		/// </summary>
		/// <param name="itemName">项的名称。</param>
		/// <returns>项的索引值。</returns>
		public int GetIndex(string itemName)
		{
			int i = 0;
			foreach(DictionaryOccupyElement item in this)
			{
				if (item.Name == itemName)
					return i;
				i++;
			}
			throw new Exception("未找到对应项。");
		}
	}


	partial class ResourceThumbnailCopyElementCollection
	{
		public ResourceThumbnailCopyElement GetItem(string name)
		{
			return (ResourceThumbnailCopyElement)BaseGet(name);
		}
	}

	partial class ResourceTypeThumbnailElementCollection
	{
		public ResourceTypeThumbnailElement GetItem(string name)
		{
			return (ResourceTypeThumbnailElement)BaseGet(name);
		}
	}

	partial class ThumbnailTypeElementCollection
	{
		public ThumbnailTypeElement GetItem(string name)
		{
			return (ThumbnailTypeElement)BaseGet(name);
		}
	}


	partial class SiteArticleContentUrlElementCollection
	{
		public SiteArticleContentUrlElement GetItem(string name)
		{
			return (SiteArticleContentUrlElement)BaseGet(name);
		}
	}

	partial class ModuleArticleContentUrlElementCollection
	{
		public ModuleArticleContentUrlElement GetItem(string name)
		{
			return (ModuleArticleContentUrlElement)BaseGet(name);
		}
	}
}